package stc.skymobi.netty.handler.codec.http.response;

import org.apache.commons.collections.Closure;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import stc.skymobi.util.Propertyable;

/**
 * @author hp
 *
 */
public abstract class DefaultBusyHandlerBySendbackResp implements Closure {

    private static final Logger logger = 
    	LoggerFactory.getLogger(DefaultBusyHandlerBySendbackResp.class);
    
    private SendbackResponseHelper sendbackHelper;
	
	/**
	 * @return the sendbackHelper
	 */
	public SendbackResponseHelper getSendbackHelper() {
		return sendbackHelper;
	}

	/**
	 * @param sendbackHelper the sendbackHelper to set
	 */
	public void setSendbackHelper(SendbackResponseHelper sendbackHelper) {
		this.sendbackHelper = sendbackHelper;
	}
	
	protected abstract Object createResponse();
	
	/* (non-Javadoc)
	 * @see org.apache.commons.collections.Closure#execute(java.lang.Object)
	 */
	public void execute(Object input) {
		if ( input instanceof Propertyable ) {
			Propertyable	req = (Propertyable)input;
			
			sendbackHelper.makeAndSendback(createResponse(), req);
		}
		else {
			logger.error(input + " is not Propertyable, Can not sendback response.");
		}
	}

	public String getResponsePrototypeAsString() {
		return	createResponse().toString();
	}
}
